package com.ruoyi.experiment.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.experiment.mapper.ExperimentDataMapper;
import com.ruoyi.experiment.domain.ExperimentData;
import com.ruoyi.experiment.service.IExperimentDataService;

/**
 * 实验数据Service业务层处理
 * 
 * @author gw
 * @date 2025-01-08
 */
@Service
public class ExperimentDataServiceImpl implements IExperimentDataService 
{
    @Autowired
    private ExperimentDataMapper experimentDataMapper;

    /**
     * 查询实验数据
     * 
     * @param dataId 实验数据主键
     * @return 实验数据
     */
    @Override
    public ExperimentData selectExperimentDataByDataId(Long dataId)
    {
        return experimentDataMapper.selectExperimentDataByDataId(dataId);
    }

    /**
     * 查询实验数据列表
     * 
     * @param experimentData 实验数据
     * @return 实验数据
     */
    @Override
    public List<ExperimentData> selectExperimentDataList(ExperimentData experimentData)
    {
        return experimentDataMapper.selectExperimentDataList(experimentData);
    }

    /**
     * 新增实验数据
     * 
     * @param experimentData 实验数据
     * @return 结果
     */
    @Override
    public int insertExperimentData(ExperimentData experimentData)
    {
        experimentData.setCreateTime(DateUtils.getNowDate());
        experimentData.setCreateBy(SecurityUtils.getUsername());
        return experimentDataMapper.insertExperimentData(experimentData);
    }

    /**
     * 修改实验数据
     * 
     * @param experimentData 实验数据
     * @return 结果
     */
    @Override
    public int updateExperimentData(ExperimentData experimentData)
    {
        experimentData.setUpdateTime(DateUtils.getNowDate());
        experimentData.setUpdateBy(SecurityUtils.getUsername());
        return experimentDataMapper.updateExperimentData(experimentData);
    }

    /**
     * 批量删除实验数据
     * 
     * @param dataIds 需要删除的实验数据主键
     * @return 结果
     */
    @Override
    public int deleteExperimentDataByDataIds(Long[] dataIds)
    {
        int deletedCount = 0;
        for (Long dataId : dataIds) {
            ExperimentData experimentData = experimentDataMapper.selectExperimentDataByDataId(dataId);
            experimentData.setDeleteBy(SecurityUtils.getUsername());
            experimentData.setDeleteTime(DateUtils.getNowDate());
            experimentData.setDelFlag(1);
            experimentDataMapper.updateExperimentData(experimentData);
            deletedCount ++;
        }
        return deletedCount;
    }

    /**
     * 删除实验数据信息
     * 
     * @param dataId 实验数据主键
     * @return 结果
     */
    @Override
    public int deleteExperimentDataByDataId(Long dataId)
    {
        ExperimentData experimentData = experimentDataMapper.selectExperimentDataByDataId(dataId);
        experimentData.setDeleteBy(SecurityUtils.getUsername());
        experimentData.setDeleteTime(DateUtils.getNowDate());
        experimentData.setDelFlag(1);
        return experimentDataMapper.updateExperimentData(experimentData);
    }
}
